<?php

namespace App\Model;

use Illuminate\Support\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\Model\SaErrorLog.
 *
 * @property int         $id
 * @property string      $message    错误信息
 * @property string      $file       错误文件
 * @property int         $line       错误代码所在具体行数
 * @property string      $ip         访问ip
 * @property string      $url        访问url
 * @property string      $method     访问方法
 * @property string      $param      访问参数
 * @property string      $header     header
 * @property int         $status     状态：0未处理，1已处理
 * @property Carbon|null $created_at 创建时间
 * @property Carbon|null $updated_at 更新时间
 * @property Carbon|null $deleted_at 删除时间
 *
 * @method static Builder|SaErrorLog newModelQuery()
 * @method static Builder|SaErrorLog newQuery()
 * @method static \Illuminate\Database\Query\Builder|SaErrorLog onlyTrashed()
 * @method static Builder|SaErrorLog query()
 * @method static Builder|SaErrorLog whereCreatedAt($value)
 * @method static Builder|SaErrorLog whereDeletedAt($value)
 * @method static Builder|SaErrorLog whereFile($value)
 * @method static Builder|SaErrorLog whereHeader($value)
 * @method static Builder|SaErrorLog whereId($value)
 * @method static Builder|SaErrorLog whereIp($value)
 * @method static Builder|SaErrorLog whereLine($value)
 * @method static Builder|SaErrorLog whereMessage($value)
 * @method static Builder|SaErrorLog whereMethod($value)
 * @method static Builder|SaErrorLog whereParam($value)
 * @method static Builder|SaErrorLog whereStatus($value)
 * @method static Builder|SaErrorLog whereUpdatedAt($value)
 * @method static Builder|SaErrorLog whereUrl($value)
 * @method static \Illuminate\Database\Query\Builder|SaErrorLog withTrashed()
 * @method static \Illuminate\Database\Query\Builder|SaErrorLog withoutTrashed()
 * @mixin \Eloquent
 */
class SaErrorLog extends BaseModel
{
    use SoftDeletes;
    protected $table = 'sa_error_log';

    /**
     * 获取错误日志列表.
     *
     * @param $where
     * @param $limit
     *
     * @return mixed
     */
    public static function getErrolLog($where, $limit)
    {
        $data = self::where($where)->orderBy('id', 'desc')->paginate($limit)->toArray();

        return $data;
    }

    /**
     * 添加错误日志.
     *
     * @param $info
     *
     * @return mixed
     */
    public static function addInfo($info)
    {
        return self::insert($info);
    }

    /**
     * 编辑错误日志.
     *
     * @param $id
     * @param $status
     *
     * @return mixed
     */
    public static function editError($id, $status)
    {
        $info['status']     = $status;

        return self::where(['id' => $id])->update($info);
    }

    /**
     * 统计错误日志数量.
     *
     * @param $where
     *
     * @return mixed
     */
    public static function getErrorCount($where)
    {
        $count = self::where($where)->count();

        return $count;
    }
}
